//
//  NMPOSersListCell.swift
//  NMPO
//
//  Created by PowerfullClean on 2023/11/1.
//

import UIKit

class NMPOSersListCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(nmpo_bgView)
        contentView.addSubview(nmpo_iconView)
        contentView.addSubview(nmpo_titleLabel)
        contentView.addSubview(nmpo_selectView)
        nmpo_bgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        nmpo_iconView.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 56, height: 32))
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(22)
        }
        nmpo_titleLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(nmpo_iconView.snp.right).offset(12)
        }
        nmpo_selectView.snp.makeConstraints { make in
            make.size.equalTo(16)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-22)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    var nmpo_serverModel: NMPOSerModel? {
        didSet {
            guard let nmpo_serverModel = nmpo_serverModel else { return  }
            
            if nmpo_serverModel.nmpo_smart {
                nmpo_titleLabel.text = "Auto choose"
                nmpo_iconView.image = UIImage(named: "nmpo_home_changeIcon")
            }else {
               
                if nmpo_serverModel.nmpo_address == "38.114.114.19" {
                    nmpo_titleLabel.text = "Los Angeles"
                }
                if nmpo_serverModel.nmpo_address == "38.68.134.105" {
                    nmpo_titleLabel.text = "Dallas"
                }
                if nmpo_serverModel.nmpo_address == "38.107.226.61" {
                    nmpo_titleLabel.text = "Ashburn 3"
                }
                if nmpo_serverModel.nmpo_address == "216.39.248.160" {
                    nmpo_titleLabel.text = "Chicago"
                }
                if nmpo_serverModel.nmpo_address == "139.64.165.239" {
                    nmpo_titleLabel.text = "Denver"
                }
                if nmpo_serverModel.nmpo_address == "38.114.114.155" {
                    nmpo_titleLabel.text = "Los Angeles"
                }
                if nmpo_serverModel.nmpo_address == "216.39.248.169" {
                    nmpo_titleLabel.text = "Chicago"
                }
                if nmpo_serverModel.nmpo_address == "38.75.137.125" {
                    nmpo_titleLabel.text = "Los Angeles"
                }
                if nmpo_serverModel.nmpo_address == "162.251.63.93" {
                    nmpo_titleLabel.text = "Los Angeles"
                }
                if nmpo_serverModel.nmpo_address == "216.173.115.84" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "38.64.138.184" {
                    nmpo_titleLabel.text = "Chicago"
                }
                if nmpo_serverModel.nmpo_address == "38.107.226.200" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "38.86.135.202" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "38.107.226.152" {
                    nmpo_titleLabel.text = "Ashburn 1"
                }
                if nmpo_serverModel.nmpo_address == "38.86.135.250" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "38.86.135.74" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "38.107.226.127" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "38.121.43.235" {
                    nmpo_titleLabel.text = "Atlanta"
                }
                if nmpo_serverModel.nmpo_address == "38.121.43.235" {
                    nmpo_titleLabel.text = "Atlanta"
                }
                if nmpo_serverModel.nmpo_address == "216.39.248.251" {
                    nmpo_titleLabel.text = "Chicago"
                }
                if nmpo_serverModel.nmpo_address == "38.64.138.244" {
                    nmpo_titleLabel.text = "Chicago"
                }
                if nmpo_serverModel.nmpo_address == "216.39.248.225" {
                    nmpo_titleLabel.text = "Chicago"
                }
                if nmpo_serverModel.nmpo_address == "38.64.138.5" {
                    nmpo_titleLabel.text = "Chicago"
                }
                if nmpo_serverModel.nmpo_address == "38.121.43.151" {
                    nmpo_titleLabel.text = "Atlanta 1"
                }
                if nmpo_serverModel.nmpo_address == "38.107.226.223" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "38.86.135.106" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "38.86.135.236" {
                    nmpo_titleLabel.text = "Ashburn"
                }
                if nmpo_serverModel.nmpo_address == "142.202.49.114" {
                    nmpo_titleLabel.text = "Ashburn 2"
                }
                if nmpo_serverModel.nmpo_address == "38.121.43.78" {
                    nmpo_titleLabel.text = "Atlanta"
                }
                if nmpo_serverModel.nmpo_address == "38.64.138.195" {
                    nmpo_titleLabel.text = "Chicago"
                }
                if nmpo_serverModel.nmpo_address == "38.68.135.115" {
                    nmpo_titleLabel.text = "Dallas"
                }
                if nmpo_serverModel.nmpo_address == "38.121.43.44" {
                    nmpo_titleLabel.text = "Atlanta 2"
                }
                if nmpo_serverModel.nmpo_address ==  "38.91.106.154" {
                    nmpo_titleLabel.text = "Miami"
                }
                if nmpo_serverModel.nmpo_address ==  "38.91.106.154" {
                    nmpo_titleLabel.text = "Miami"
                }
                if nmpo_serverModel.nmpo_address ==  "139.64.165.86" {
                    nmpo_titleLabel.text = "Denver"
                }
               
                if nmpo_titleLabel.text?.count ?? 0 > 0 {
                    nmpo_serverModel.nmpo_country = "USA"
                    nmpo_titleLabel.text = (nmpo_serverModel.nmpo_country ?? "") + "-" + (nmpo_titleLabel.text ?? "")
                }else {
                    nmpo_titleLabel.text = nmpo_serverModel.nmpo_country
                }
                nmpo_iconView.image = UIImage(named: nmpo_serverModel.nmpo_icon ?? "")
                
            }
            
            nmpo_selectView.image = UIImage(named: nmpo_serverModel.nmpo_select ? "nmpo_list_select" : "nmpo_list_unselect")
        }
    }
    lazy var nmpo_iconView: UIImageView = {
        let nmpo_iconView = UIImageView(image: UIImage(named: "nmpo_setting_rate"))
        return nmpo_iconView
    }()
    lazy var nmpo_titleLabel: UILabel = {
        let nmpo_titleLabel = UILabel()
        nmpo_titleLabel.font = UIFont.systemFont(ofSize: 14)
        nmpo_titleLabel.textColor = NMPOCommon.nmpo_getHXColorValue(rgb: 0xFFFFFF)
       
        return nmpo_titleLabel
    }()
    lazy var nmpo_bgView: UIImageView = {
        let nmpo_bgView = UIImageView(image: UIImage(named: "nmpo_list_other"))
        return nmpo_bgView
    }()
    lazy var nmpo_selectView: UIImageView = {
        let nmpo_selectView = UIImageView(image: UIImage(named: "nmpo_list_unselect"))
        return nmpo_selectView
    }()
}

